import 'package:get/get_instance/src/extension_instance.dart';
import 'package:video_player/video_player.dart';
import 'package:flutter/material.dart';
import 'package:get/route_manager.dart';

import 'auth_controller.dart';

class Intro extends StatefulWidget {
  @override
  _IntroState createState() => _IntroState();
}

class _IntroState extends State<Intro> {
  final controller = Get.find<AuthController>();
  late VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.asset('assets/test/love.mp4');

    _controller.addListener(() {
      setState(() {});
    });
    _controller.setLooping(true);
    _controller.initialize().then((_) => setState(() {}));
    _controller.play();
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      child: Stack(
        children: [
          Container(
            color: Colors.black,
            width: double.infinity,
            height: double.infinity,
            alignment: Alignment.center,
            child: Container(
              width: MediaQuery.of(context).size.width,
              height: double.infinity,
              child: ColorFiltered(
                colorFilter: ColorFilter.mode(Colors.grey, BlendMode.modulate),
                child: AspectRatio(
                  aspectRatio: _controller.value.aspectRatio,
                  child: VideoPlayer(_controller),
                ),
              ),
            ),
          ),
          Positioned(
              right: 20,
              top: 80,
              child: Text("随便看看",
                  style: TextStyle(color: Colors.white, fontSize: 16))),
          Positioned(
              left: 40,
              top: 180,
              child: Text("smile",
                  style: TextStyle(
                      color: Colors.white,
                      fontSize: 26,
                      fontWeight: FontWeight.bold))),
          Positioned(
              left: 40,
              top: 220,
              child: Text("欢迎加入👏",
                  style: TextStyle(
                      color: Colors.white,
                      fontSize: 34,
                      fontWeight: FontWeight.bold))),
          Align(
            alignment: Alignment(0, .8),
            child: TextButton(
              onPressed: () {
                _controller.pause();
                Get.toNamed('/introduce/login', arguments: controller)
                    ?.then((value) {
                  _controller.play();
                });
              },
              child: Container(
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(100),
                  color: Colors.white,
                ),
                alignment: Alignment.center,
                height: 60,
                width: 280,
                child: Text(
                  "手机号登录或者注册",
                  style: TextStyle(color: Colors.black, fontSize: 16),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }

  void didChangeAppLifecycleState(AppLifecycleState state) {
    _controller.dispose();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
}
